package com.mebs.edi.model.edi.e211;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import com.mebs.edi.model.dom.DomChild;
import com.mebs.edi.model.dom.DomChildren;
import com.mebs.edi.model.dom.DomEntity;
import com.mebs.edi.model.edi.EdiSt;
import com.mebs.model.logistics.Transportation;

/**
 * 
 * ST section (representing Transportation) of a 211 EDI file 
 * 
 * @author nit
 *
 */
@Entity()
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "edi_211_st")
@PrimaryKeyJoinColumn(name = "Id")
@DomEntity(name = "ST", discriminatorAttribute = "ST01", discriminatorValues = {"211"})
public class Edi211St extends EdiSt {
	
	@Embedded
	@DomChild
	private Edi211Bol bol;
	
	@Embedded
	@DomChild
	private Edi211B2a b2a;
	
	@Embedded
	@DomChild
	private Edi211Ms3 ms3;
	
	@Embedded
	@DomChild
	private Edi211G62 g62;
	
	@Embedded
	@DomChild(offset = 1)
	private Edi211G62 g62_1;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "st_id")
	@DomChildren
	private List<Edi211Nn> nnSections;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "st_id")
	@DomChildren
	private List<Edi211At> atSections;
	
	public Edi211St() {
		super();
	}

	public List<Edi211Nn> getNnSections() {
		return nnSections;
	}

	public void setNnSections(List<Edi211Nn> nnSections) {
		this.nnSections = nnSections;
	}

	public List<Edi211At> getAtSections() {
		return atSections;
	}

	public void setAtSections(List<Edi211At> atSections) {
		this.atSections = atSections;
	}

	public Edi211Bol getBol() {
		return bol;
	}

	public void setBol(Edi211Bol bol) {
		this.bol = bol;
	}

	public Edi211B2a getB2a() {
		return b2a;
	}

	public void setB2a(Edi211B2a b2a) {
		this.b2a = b2a;
	}

	public Edi211Ms3 getMs3() {
		return ms3;
	}

	public void setMs3(Edi211Ms3 ms3) {
		this.ms3 = ms3;
	}

	public Edi211G62 getG62() {
		return g62;
	}

	public void setG62(Edi211G62 g62) {
		this.g62 = g62;
	}

	public Edi211G62 getG62_1() {
		return g62_1;
	}

	public void setG62_1(Edi211G62 g62_1) {
		this.g62_1 = g62_1;
	}

	

	@Override
	public String toString() {
		return "Edi211St [bol=" + bol + ", b2a=" + b2a + ", ms3=" + ms3 + ", g62=" + g62 + ", g62_1=" + g62_1
				+ ", nnSections=" + nnSections + ", atSections=" + atSections + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((atSections == null) ? 0 : atSections.hashCode());
		result = prime * result + ((b2a == null) ? 0 : b2a.hashCode());
		result = prime * result + ((bol == null) ? 0 : bol.hashCode());
		result = prime * result + ((g62 == null) ? 0 : g62.hashCode());
		result = prime * result + ((g62_1 == null) ? 0 : g62_1.hashCode());
		result = prime * result + ((ms3 == null) ? 0 : ms3.hashCode());
		result = prime * result + ((nnSections == null) ? 0 : nnSections.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Edi211St other = (Edi211St) obj;
		if (atSections == null) {
			if (other.atSections != null)
				return false;
		} else if (!atSections.equals(other.atSections))
			return false;
		if (b2a == null) {
			if (other.b2a != null)
				return false;
		} else if (!b2a.equals(other.b2a))
			return false;
		if (bol == null) {
			if (other.bol != null)
				return false;
		} else if (!bol.equals(other.bol))
			return false;
		if (g62 == null) {
			if (other.g62 != null)
				return false;
		} else if (!g62.equals(other.g62))
			return false;
		if (g62_1 == null) {
			if (other.g62_1 != null)
				return false;
		} else if (!g62_1.equals(other.g62_1))
			return false;
		if (ms3 == null) {
			if (other.ms3 != null)
				return false;
		} else if (!ms3.equals(other.ms3))
			return false;
		if (nnSections == null) {
			if (other.nnSections != null)
				return false;
		} else if (!nnSections.equals(other.nnSections))
			return false;
		return true;
	}
}
